<?php
/* 
 * FilePath: rwmsp-app\Consumer.php
 * Created: lijianwei 2021-05-26 11:01:16
 * -----
 * Last Modified: lijianwei 2021-05-26 17:31:31
 * -----
 * Copyright (c) 2016-2021 Rongwen Tech Ltd.
 * -----
 */

//生产消费者模式 demo

// 消费者代码[LowLevel]
$rk = new \RdKafka\Consumer();
$rk->setLogLevel(LOG_DEBUG);
$rk->addBrokers("127.0.0.1");

$topic = $rk->newTopic("TopicTest");

$topic->consumeStart(0, RD_KAFKA_OFFSET_BEGINNING);

while (true) {
    $msg = $topic->consume(0, 1000);
    if (null === $msg) {
        continue;
    } elseif ($msg->err) {
        echo $msg->errstr(), "\n";
        break;
    } else {
        echo $msg->payload, "\n";
    }
    // $topic->consumeSync();
}
